//
// Created by redcat1 on 03.05.2024.
//

#ifndef TASK_ARRAY_TEST_DSL_H
#define TASK_ARRAY_TEST_DSL_H

#include <string>

#define TEST(suite_name, test_name)     \
  void Test##suite_name##_##test_name()

#define TEST_RUN(suite_name, test_name)                                      \
  std::cout << "--------\n";                                                 \
  std::cout << "Running test " << #suite_name << "." << #test_name << ":\n"; \
  Test##suite_name##_##test_name()

#define ASSERT_EQ(expected, actual) \
  if (expected == actual)           \
    OkMsg();                        \
  else                              \
    ErrorMsg(expected, actual);

#define ASSERT_NEAR(expected, actual, eps) \
  if (std::fabs(expected - actual) < eps)  \
    OkMsg();                               \
  else                                     \
    ErrorMsg(std::to_string(expected), std::to_string(actual));

#define ASSERT_THROW(exception, expression)     \
  try                                           \
  {                                             \
    expression; /*throws exception*/            \
    ErrorMsg("", "");                           \
  }                                             \
  catch(exception& e)                           \
  {                                             \
    OkMsg(); /*we caught it*/                   \
    std::cout << "\t" << e.what() << std::endl; \
  }                                             \
  catch (...)                                   \
  {                                             \
    ErrorMsg("", "");                           \
  }

void OkMsg();
void ErrorMsg(const std::string& expected, const std::string& actual);

#endif //TASK_ARRAY_TEST_DSL_H
